///对应阿里云 SDK 下载的 MediaInfo class
class DownloadModel {
  late String videoId;
  late String title;
  late String coverUrl;
  late List<TrackInfoModel> trackInfos;

  DownloadModel({this.videoId = "", this.title = "", this.coverUrl = "",  this.trackInfos = const []});

  DownloadModel.fromJson(Map<String, dynamic> jsonMap) {
    videoId = jsonMap['mVideoId'] ?? "";
    title = jsonMap['mTitle'] ?? "";
    coverUrl = jsonMap['mCoverUrl'] ?? "";
    if (jsonMap['mTrackInfos'] != null) {
      trackInfos = [];
      jsonMap['mTrackInfos'].forEach((v) {
        trackInfos.add(TrackInfoModel.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = Map<String, dynamic>();
    data['mVideoId'] = this.videoId;
    data['mTitle'] = this.title;
    data['mCoverUrl'] = this.coverUrl;
    if (this.trackInfos.isNotEmpty) {
      data['mTrackInfos'] = this.trackInfos.map((e) => e.toJson()).toList();
    }
    return data;
  }
}

class TrackInfoModel {
  late int index;
  late int vodFileSize;
  late String vodFormat;
  late String vodDefinition;

  TrackInfoModel(
      {this.index = 0, this.vodFileSize = 0, this.vodFormat = "", this.vodDefinition = ""});

  TrackInfoModel.fromJson(Map<String, dynamic> jsonMap) {
    index = jsonMap['index'];
    vodFileSize = jsonMap['vodFileSize'];
    vodFormat = jsonMap['vodFormat'];
    vodDefinition = jsonMap['vodDefinition'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = Map<String, dynamic>();
    data['index'] = this.index;
    data['vodFileSize'] = this.vodFileSize;
    data['vodFormat'] = this.vodFormat;
    data['vodDefinition'] = this.vodDefinition;
    return data;
  }
}
